package com.gxa.modules.app.login.controller;

import com.gxa.common.utils.Result;
import com.gxa.modules.app.login.dto.LoginFormDto;
import com.gxa.modules.app.login.service.PhoneLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PhoneController
 * @Description 手机号码登录
 * @Author Mr.YUAN
 * @Date 2022/11/15 19:56
 */

@RestController
@Api(tags = "手机号码登录")
@RequestMapping("/phone")
@Slf4j
public class PhoneController {

    @Autowired
    private PhoneLoginService phoneLoginService;

    @ApiOperation(value = "获取验证码")
    @GetMapping("/code")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "phone",value = "手机号码",dataType = "String"),
    })
    public Result getCode(String phone) {

        return phoneLoginService.sendCode(phone);
    }

    @ApiOperation(value = "使用验证码登录")
    @PostMapping("/login")
    public Result toLogin(@RequestBody LoginFormDto loginFormDto) {

        log.info("----{}---->"+loginFormDto.getCode());
        log.info("----{}---->"+loginFormDto.getPhone());
        return phoneLoginService.login(loginFormDto);
    }

}